package com.doubi.controller.sysDic;

import com.doubi.common.aspectj.annotation.SysLog;
import com.doubi.model.sys.TProvince;
import com.doubi.service.ProvinceService;
import com.doubi.utils.DataUtil;
import com.doubi.vo.AppModel;
import com.doubi.vo.PageVo;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 省份 信息操作处理
 *
 * @author MrDoubi
 * @date 2019-05-29 19:23:14
 */
@Controller
@RequestMapping("province")
public class ProvinceController {

    @Autowired
    private ProvinceService provinceService;

    /**
     * 功能描述：进入页面
     * @author   MrDoubi 2019-06-29 16:37
     * @return      返回页面路径
     */
    @RequiresPermissions("province:view")
    @GetMapping("view")
    public String list() {
        return "web/province/view";
    }

    /**
     * 功能说明：查询省份分页列表
     * @author MrDoubi
     * @date 2019-05-29 19:23:14
     */
    @SysLog(title = "查询省份分页列表")
    @RequiresPermissions("province:page")
    @PostMapping("page")
    @ResponseBody
    public PageVo<TProvince> getPage(PageVo<TProvince> page, TProvince province) {
        return provinceService.getPage(page, province);
    }


    /**
     * 功能说明：查询省份列表
     * @author MrDoubi
     * @date 2019-05-29 19:23:14
     */
    @SysLog(title = "查询省份列表")
    @RequiresPermissions("province:list")
    @PostMapping("list")
    @ResponseBody
    public List<TProvince> getList(TProvince province) {
        return provinceService.getList(province);
    }

    /**
     * 功能说明：修改省份
     * @author MrDoubi
     * @date 2019-05-29 19:23:14
     */
    @RequiresPermissions(value = {"province:edit", "province:add"}, logical = Logical.OR)
    @GetMapping("edit")
    public String edit(TProvince province, Model model) {
        if (DataUtil.isNotEmpty(province.getProvinceOid())) {
            province = provinceService.getBean(province.getProvinceOid());
        }
        model.addAttribute("bean", province);
        return "web/province/edit";
    }

    /**
     * 功能说明：保存省份
     * @author MrDoubi
     * @date 2019-05-29 19:23:14
     */
    @SysLog(title = "保存省份")
    @RequiresPermissions("province:saveOrUpdate")
    @PostMapping("saveOrUpdate")
    @ResponseBody
    public AppModel saveOrUpdate(TProvince province) {
        return provinceService.saveOrUpdateBean(province);
    }

    /**
     * 功能说明：删除省份
     * @author MrDoubi
     * @date 2019-05-29 19:23:14
     */
    @SysLog(title = "删除省份")
    @RequiresPermissions("province:delBean")
    @PostMapping("delBean")
    @ResponseBody
    public AppModel delBean(TProvince province) {
        return provinceService.delBean(province);
    }

    /**
     * 功能说明：省份状态更新 接口
     * @author  MrDoubi 2019-01-10 15:14:33
     * @param province bean
     * @return model
     */
    @SysLog(title = "省份状态更新 接口")
    @RequiresPermissions("province:updateStatus")
    @PostMapping("updateStatus")
    @ResponseBody
    public AppModel updateStatus(TProvince province){
        return provinceService.updateStatus(province);
    }

    /**
     * 功能说明：更新redis中的省市区 接口
     * @author  MrDoubi 2019-01-10 15:14:33
     * @return model
     */
    @SysLog(title = "更新redis中的省市区 接口")
    @RequiresPermissions("province:updateAreaRedis")
    @PostMapping("updateAreaRedis")
    @ResponseBody
    public AppModel updateAreaRedis(){
//        return provinceService.updateAreaRedis();
        return null;
    }



    /**
     * 功能说明：更新redis中的省市区 接口
     * @author  MrDoubi 2019-01-10 15:14:33
     * @return model
     */
    @SysLog(title = "更新库中的省市区和高德同步")
    @RequiresPermissions("province:updateInitGaoDe")
    @PostMapping("updateInitGaoDe")
    @ResponseBody
    public AppModel updateInitGaoDe(){
        //return provinceService.updateInitGaoDe();
        return null;
    }
}
